<template>
	<transition name="el-zoom-in-center">
		<div class="JNPF-preview-main">
			<div class="JNPF-common-page-header">
				<el-page-header @back="goBack" :content="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"/>
				<div class="options">
					<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
					<el-button @click="goBack">取 消</el-button>
				</div>
			</div>
			<el-row :gutter="15"  class="main" :style="{margin: '0 auto',width:'100%'}">
			<el-form ref="elForm" :model="dataForm" size="medium" label-width="100px" label-position="right" :disabled="!!isDetail" :rules="rules">
				<el-col :span="24">
					<el-form-item label="风险点" prop="fxd" required >
						<el-select v-model="dataForm.fxd" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in fxdOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="风险点类型" prop="fxdlx" required >
						<el-select v-model="dataForm.fxdlx" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in fxdlxOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="排查人" prop="pcr" required >
						<el-select v-model="dataForm.pcr" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in pcrOptions" :key="index" :label="item.F_RealName" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="排查状态" prop="pczt" required >
						<el-select v-model="dataForm.pczt" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in pcztOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="排查计划ID" prop="pcjhid" required >
						<el-input v-model="dataForm.pcjhid" placeholder="请输入" clearable disabled :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
			</el-form>
			</el-row>
		</div>
	</transition>

</template>
<script>
import request from '@/utils/request'
import {getDictionaryDataSelector}from '@/api/systemData/dictionary'
import {previewDataInterface}from '@/api/systemData/dataInterface'
export default {
    data() {
      return {
        visible: false,
        isDetail: false,
        dataForm: {
					fxd:undefined,
					fxdlx:undefined,
					pcr:undefined,
					pczt:undefined,
					pcjhid:undefined,

        },
        rules: {
						fxd:[
						{
							required:true,
							message:'请输入风险点',
							trigger:'blur'
						},
						],
						fxdlx:[
						{
							required:true,
							message:'请输入风险点类型',
							trigger:'blur'
						},
						],
						pcr:[
						{
							required:true,
							message:'请输入排查人',
							trigger:'blur'
						},
						],
						pczt:[
						{
							required:true,
							message:'请输入排查状态',
							trigger:'blur'
						},
						],
						pcjhid:[
						{
							required:true,
							message:'请输入排查计划ID',
							trigger:'blur'
						},
						],

        },
				fxdOptions:[{"fullName":"选项一","id":"0"},{"fullName":"选项二","id":"1"}],
				fxdlxOptions:[{"fullName":"选项一","id":"0"},{"fullName":"选项二","id":"1"}],
				pcrOptions:[],
				pcztOptions:[{"fullName":"待排查","id":"待排查"},{"fullName":"已排查","id":"已排查"}],


      }
    },
    created() {
		this.getpcrOptions();

    },
    methods: {
		getpcrOptions()
		{
			previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
				this.pcrOptions = res.data
			})
		},

           goBack() {
                    this.$emit('refresh1')
                },
      init(id, isDetail) {

        this.dataForm.id = id || 0;
        this.visible = true;
        this.isDetail = isDetail || false;
        this.$nextTick(() => {
          this.$refs['elForm'].resetFields();
          if (this.dataForm.id) {
            request({
              url: '/api/System/pcjhfxd/' + this.dataForm.id,
              method: 'get'
            }).then(res =>{
              this.dataForm = res.data;

            })
          }
        })
      },
      // 表单提交
      dataFormSubmit() {

        this.$refs['elForm'].validate((valid) => {
          if (valid) {
            if (!this.dataForm.id) {
              request({
                url: '/api/System/pcjhfxd',
                method: 'post',
                data: this.dataForm,
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh1', true);
                  }
                })
              })
            } else {
              request({
                url: '/api/System/pcjhfxd/' + this.dataForm.id,
                method: 'PUT',
                data: this.dataForm
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh1', true);
                  }
                })
              })
            }
          }
        })
      },

    }
  }
  </script>